#include "Base.h"

#include <string>
#include <map>

template<class T>
class CMapManager
{
public:
	typedef std::map<std::string, T*> TMapResource;
protected:
	
	//typedef TMapResource::iterator TMapResourceIt;
	TMapResource m_Resources;
	
public:

	CMapManager(){}
	~CMapManager(){Destroy();}

	virtual T * GetResource(const std::string &Name)
	{
		TMapResource::iterator it=m_Resources.find(Name);
		if(it==m_Resources.end()) return m_Resources[Name];
		LOGGER->AddNewLog(ELL_ERROR, "No se encontro el resource en el mapa");
		return NULL;
	}

	virtual void AddResource(const std::string &Name, T *Resource)
	{
		TMapResource::iterator it=m_Resources.find(Name);
		if(it==m_Resources.end()) m_Resources[Name]=Resource;
		else LOGGER->AddNewLog(ELL_ERROR, "El Resource ya se encuentra agregado en el mapa");
	}

	void RemoveResource(const std::string &Name)
	{
		TMapResources::iterator it=m_ResourcesMap.find(Name);
		if(it!=m_Resource.end()) m_Resource.erase(it);
		else LOGGER->AddNewLog(ELL_ERROR, "No hay elementos con ese name");
	}
	
	void Destroy() //recorrer mapa y borrar al terminar el bucle se libera el mapa
	{
		for(TMapResource::iterator it=m_Resources.begin();it!=m_Resources.end();++it)
		{
			CHECKED_DELETE(it->second)
		}
		//CHECKED_RELEASE( m_Resources);
		
	}
};
